package com.cn.task.timer;

import java.util.TimerTask;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * FUN: 调度定时器
 *
 * @author sushy
 * @date 2016-3-23 
 */
public class SchedulerTimerTask extends TimerTask{

	protected final Log logger = LogFactory.getLog(getClass());
	private SchedulerTask schedulerTask;
	private String className;

	public SchedulerTimerTask(SchedulerTask schedulerTask) {
		this.schedulerTask = schedulerTask;
		this.className = schedulerTask.getClass().getSimpleName();
	}

	public void run() {
		try {
			logger.info(className + " start!");
			schedulerTask.runTask();
		} catch (Throwable t) {
			logger.error(className + " error!", t);
		} finally {
			logger.info(className + " end!");
		}

		//重新调度
		schedulerTask.reschedule();
	}

}
